﻿using System;
using System.Configuration;
using System.Web.Mvc;
using System.Web.MVC;
using System.Web.Security;
using NTQOnlineExam.Services.CommandService;
using NTQOnlineExam.Services.CommandService.Content;
using NTQOnlineExamFrontend.Models;

namespace NTQOnlineExamFrontend.Controllers
{
    public class ContentController : Controller
    {
        private readonly IContentCommandService _contentCommandService;

        public ContentController(IContentCommandService contentCommandService)
        {
            _contentCommandService = contentCommandService;
        }

        [HttpGet]
        public ActionResult HomePage()
        {
            ViewBag.HideTitle = true;
            return View();
        }

        [HttpGet]
        public ActionResult AboutUs()
        {
            return View();
        }

        [HttpGet]
        public ActionResult FeeAndTrialExams()
        {
            return View();
        }

        [HttpGet]
        public ActionResult FAQ()
        {
            return View();
        }

        [HttpGet]
        public ActionResult ContactUs()
        {
            return View();
        }


        [HttpPost]
        [AllowAnonymous]
        public ActionResult RequestContact(ContactViewModel model)
        {
            try
            {
                var recipient = ConfigurationManager.AppSettings["ContactSupportEmail"];
                var bcc = ConfigurationManager.AppSettings["BccContactSupportEmail"];
                _contentCommandService.SendContactEmail(new SendContactCommand() { Email = model.Email, Message = model.Message, Name = model.Name, Recipient = recipient, BccRecipient = bcc });
                return ModelState.JsonValidation(new { Success = true });
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Request Contact", Resources.Content.ContactError);
            }
            return ModelState.JsonValidation();

        }
    }
}
